package com.gitee.yusugar.core.annotation;

import com.gitee.yusugar.core.util.LogUtil;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

public class InitLogUtilBeanByImportSelector implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions( AnnotationMetadata annotationMetadata, BeanDefinitionRegistry beanDefinitionRegistry ) {
        AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap( annotationMetadata.getAnnotationAttributes( EnableLogRecord.class.getName() ) );

        if ( annotationAttributes != null ) {
            // 设置包路径
            LogUtil.basePackage = annotationAttributes.getString( "basePackage" );
            /*// 获取注解设置的包路径
            String basePackage = annotationAttributes.getString( "basePackage" );

            // 构建 LogRecord 对象
            BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( LogRecord.class);
            // 设置 basePackage 值为注解里配置的
            builder.addPropertyValue( "basePackage", basePackage );

            // 注册 Bean
            beanDefinitionRegistry.registerBeanDefinition( "logRecord", builder.getBeanDefinition() );*/
        }
    }
}
